<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改订单')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-order-edit" th:object="${carOrder}">
        <h4 class="form-header h4">订单信息</h4>
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-2 control-label">客户名称：</label>
            <div class="col-sm-9">
                <div class="form-control-static" th:text="*{userName}">
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">订单状态：</label>
            <div class="col-sm-9">
                <div class="form-control-static" th:with="type=${@dict.getType('sys_order_status')}">
                    <div th:each="dict : ${type}" th:if="${carOrder.status==dict.dictValue}"
                         th:text="${dict.dictLabel}"></div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">名称：</label>
            <div class="col-sm-9">
                <div class="form-control-static" th:text="*{orderName}">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">销售金额：</label>
            <div class="col-sm-9">
                <div class="form-control-static" th:text="*{salesPrice}">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">是否支付：</label>
            <div class="col-sm-9">
                <div class="form-control-static" th:with="type=${@dict.getType('sys_yes_no')}">
                    <div th:each="dict : ${type}" th:if="${carOrder.isPay==dict.dictValue}"
                         th:text="${dict.dictLabel}"></div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">付款时间：</label>
            <div class="col-sm-9">
                <div class="form-control-static" th:text="${#dates.format(carOrder.paymentTime, 'yyyy-MM-dd')}">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">备注：</label>
            <div class="col-sm-9">
                <div class="form-control-static" th:text="*{remark}">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">收货人名字：</label>
            <div class="form-control-static" th:text="*{userName}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">省名：</label>
            <div class="form-control-static" th:text="*{provinceName}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">市名：</label>
            <div class="form-control-static" th:text="*{cityName}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">区名：</label>
            <div class="form-control-static" th:text="*{countyName}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">详情地址：</label>
            <div class="form-control-static" th:text="*{detailInfo}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">电话号码：</label>
            <div class="form-control-static" th:text="*{telNum}">
            </div>
        </div>
        <h4 class="form-header h4" style="margin-bottom: 0px">清单明细信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table">
                    </table>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>

<script th:inline="javascript">
    var prefix = ctx + "eat/order";
    $("#form-order-edit").validate({
        focusCleanup: true
    });


    $(function () {
        var options = {
            data: [[${carOrder.carOrderItemList}]],
            pagination: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
            columns: [
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                        var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                        return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'goodName',
                    align: 'center',
                    title: '商品'
                },


                {
                    field: 'goodAmount',
                    align: 'center',
                    title: '数量'
                },


                {
                    field: 'goodPrice',
                    align: 'center',
                    title: '价格'
                },]
        };
        $.table.init(options);
    });

    function addRow() {
        var count = $("#" + table.options.id).bootstrapTable('getData').length;
        sub.editRow();

        $("#" + table.options.id).bootstrapTable('insertRow', {
            index: count,
            row: {
                index: $.table.serialNumber(count),
                goodId: "",
                goodName: "",
                goodAmount: "",
                goodPrice: ""

            }
        });
    }

    function getCountPrice() {

        var goodsIds = new Array();
        var salesPrice = 0;
        var i = 1;
        $("#bootstrap-table .goods-select").each(function () {
            console.log(i++)
            var value = $(this).val();
            if (value) {
                var index = $(this).attr("data-index");
                if (goodsIds.indexOf(value) > -1) {
                    // $(this).find("option[value='" + value + "']").val("");
                }
                goodsIds.push(value);
                var price = $(this).find("option[value='" + value + "']").attr("data-price");
                $("input[name='carOrderItemList[" + index + "].goodName']").val($(this).find("option[value='" + value + "']").text());
                var count = $("input[name='carOrderItemList[" + index + "].goodAmount']").val();

                if (count <= 0) {
                    $("input[name='carOrderItemList[" + index + "].goodAmount']").val(1);
                    count = 1;
                }
                if (undefined != price && count > 0) {
                    var countPrice = count * price;
                    $("input[name='carOrderItemList[" + index + "].goodPrice']").val(countPrice);
                    salesPrice += countPrice;
                }


            }
        })

        $("input[name='salesPrice']").val(salesPrice);


    }
</script>
</body>
</html>
